import axios from "./request";
import store from "@/store";

/**
 * 权限列表
 * @param {*} form
 * @returns
 */
export function createRolePermissionTree() {
	return axios
		.get(`rbac/menu/list`, {
			params: {},
		})
		.then((result) => {
			// store.state.queryTasksAccordingToPlan.response = result.data;
			return Promise.resolve(result);
		});
}


/**
 * 获取角色
 * @param {*} form
 * @returns
 */
export function getRoleDetailInfo(form) {
	return axios
		.get(`rbac/sys/role/get/${form.id}`, {
			params: {},
		})
		.then((result) => {
			// store.state.queryTasksAccordingToPlan.response = result.data;
			return Promise.resolve(result);
		});
}

/**
 * 新增或修改角色
 * @param {*} form
 * @returns
 */
export function createRole(form) {
	console.log("form", form);
	let s
	if (form.id === false) {
		s = 'save'
	} else {
		s = 'update'
	}
	return axios
		.post(`rbac/sys/role/${s}`, {
			params: {
				'roleId': form.id || null,
				'roleName': form.roleName,
				'remark': form.remark,
				'roleStatus': form.roleStatus,
				'roleCode': form.roleCode,
				'menuIdList': form.menuIdList.join(",")
			},
		})
		.then((result) => {
			//console.log(result);
			// store.state.queryTasksAccordingToPlan.response = result.data;
			return Promise.resolve(result);
		});
}




// 获取计划列表
export function queryPlanAccordingToTheTask(params = { pageNumber: 1, pageSize: 10 }) {
	if (localStorage.getItem('SYS_TYPE')) {
		params.systemTypeList = localStorage.getItem('SYS_TYPE');
	}
	return axios
		.get(`task/task/queryPlanAccordingToTheTask`, {
			params
		})
		.then((res) => {
			store.state.queryPlanAccordingToTheTask.response = res.data;
			return Promise.resolve(res);
		});
}





// 获取计划列表
export function queryMyPlan(params = { pageNumber: 1, pageSize: 10 }) {

	if (localStorage.getItem('SYS_TYPE')) {
		params.systemTypeList = localStorage.getItem('SYS_TYPE');
	}

	return axios
		.get(`task/task/queryMyPlan`, {
			params
		})
		.then((res) => {
			return Promise.resolve(res);
		});
}




/**
 * 我的任务
 * @param {*} current
 * @param {*} pageSize
 * @param {*} planName
 * @param {*} planStatus
 * @returns
 */
export function queryTasksAccordingToPlan(params = { pageNumber: 1, pageSize: 10 }) {
	return axios
		.get(`task/task/queryTasksAccordingToPlan`, {
			params
		})
		.then((result) => {
			store.state.queryTasksAccordingToPlan.response = result.data;
			return Promise.resolve(result);
		});
}

/**
 *
 * @param {*} pageNumber
 * @param {*} pageSize
 * @returns
 */
export function getSubjectInfoList(params = {
	pageNumber:1,
	pageSize:10,
	systemType
}) {
	
	return axios.get(`rbac/data/subject/getSubjectInfoList`, { params:params })
}

/**
 * 获取地塘快
 * @param {*} pageNumber
 * @param {*} pageSize
 * @returns
 */
export function ProductionInformationBase(params) {
	return axios
		.get(`rbac/data/LandInfo/getList`, {
			params: params
		})
		.then((result) => {
			return Promise.resolve(result);
		});
}


/**
 * UserControl
 * @param {*} pageNumber
 * @param {*} pageSize
 * @returns
 */
export function UserControl(pageNumber = 1, pageSize = 10, organId = 0, status = 1, registerTele, keywords,registerCard, userLevelQuery) {

	let params = {
		pageNumber,
		pageSize,
		organId,
		status,
		registerTele,
		keywords,
		userLevelQuery,
		registerCard
	}

	if (organId === null) {
		delete params.organId
	}
	return axios
		.get(`rbac/sysuser/list`, {
			params
		})
}


/**
 * UserControl
 * @param {*} pageNumber
 * @param {*} pageSize
 * @returns
 */

// http://192.168.105.96:8280/rbac/sys/organ/get
export function Organization() {
	return axios
		.get(`rbac/sys/organ/get`)
		.then((result) => {
			// store.state.queryTasksAccordingToPlan.response = result.data;
			return Promise.resolve(result);
		});
}

export function setPlotMSG() {
	return Promise.resolve(1)
}



/**
 * 修改和新增组织机构
 * @param {*} form
 * @returns
 */
export function createOriganOnSubmit(form) {
	let s
	if (form.id) {
		s = 'put'
	} else {
		s = 'add'
	}
	return axios
		.post(`rbac/sys/organ/${s}`, {
			params: {
				'id': form.id || null,
				'organCode': form.number,
				'organName': form.name,
				'linkMan': form.linkman,
				'linkPhone': form.phone,
				'organShortName': form.abbreviation,
				'organAddress': form.detailedAddress,
				'organMemo': form.organMemo,
				'organParent': form.superior[form.superior.length - 1] || form.organParent
			},
		})
		.then((result) => {
			//console.log(result);
			// store.state.queryTasksAccordingToPlan.response = result.data;
			return Promise.resolve(result);
		});
}
